<template>
  <van-address-list
    v-model="address.chooseId"
    :list="addressList"
    default-tag-text="默认"
    @add="onAdd"
    @edit="onEdit"
  />
  <van-popup
    v-model:show="showPop"
    position="bottom"
    :style="{ height: '60%' }"
  >
    <Edit @close-pop="showPop = false" />
  </van-popup>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { showToast } from "vant";
import Edit from "./edit.vue";
import { storeToRefs } from "pinia";
import { useAddress } from "../../store/address";
// const chosenAddressId = ref("1");
const address = useAddress();
const { addressList } = storeToRefs(address);

const onAdd = () => {
  showPop.value = true;
  address.editIdx = -1;
};
const onEdit = (item: any, index: number) => {
  // console.log(item, index);
  showPop.value = true;
  address.editIdx = index;
};

// 弹窗控制
const showPop = ref<boolean>(false);
</script>

<style scoped></style>
